// pages/stockDetail/stockDetail.js
var api = require('../../utils/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    stockDetailList:[]
  },
//跳转库存明细
  toMingxi(e){
    var stockId = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../stockMingxi/stockMingxi?stockId=' + stockId,
    })
  },

  //跳转操作库存
  opration(e){
    console.log(e)
    var type = e.currentTarget.dataset.type;
    var stockId = e.currentTarget.dataset.id;
    var itemId = e.currentTarget.dataset.itemid;
    console.log(itemId)
    wx.navigateTo({
      url: '../opratStock/opratStock?type=' + type + '&stockId=' + stockId + '&itemId=' + itemId,
    })
  },

  //获取库存详情列表
  getStockDetails(page){
    api.fetchApi('reception/details', { token: wx.getStorageSync('token'), page, id: this.data.stockId }).then(res=>{
      var stockDetailList = this.data.stockDetailList;
      var stockDetailList1=res.data;
      if (stockDetailList1.length == 0 && page > 1) {
        api.showToast('到底啦!', 'http://qnwmfx.laigl.com/iconimg/warn.png', 1500)
        return
      }
      stockDetailList = [...stockDetailList, ...stockDetailList1]
      this.setData({
        stockDetailList,
        page,
        expenditure: res.expenditure,
        give: res.give,
        income: res.income,
        num: res.num,
        sellout: res.sellout,
        total: res.total,
        stockId:res.id
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var stockId = options.stockId;
    this.setData({
      stockId
    })

    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getStockDetails(1)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
this.setData({
  stockDetailList:[]
})
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var page = this.data.page || 1;
    page++;

    this.getStockDetails(page)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})